from django.db import models
from django.contrib.auth.models import User

class Asker(models.Model):
    user = models.OneToOneField(User)
    
    def __unicode__(self):
        return self.user.username
    
class Doer(models.Model):
    user = models.OneToOneField(User)
    
    def __unicode__(self):
        return self.user.username

class Project(models.Model):
    name = models.CharField(max_length=200)
    description = models.TextField()
    
    def __unicode__(self):
        return self.name

class Release(models.Model):
    name = models.CharField(max_length=200)
    start_date = models.DateTimeField(null=True)
    target_date = models.DateTimeField(null=True)
    
    project = models.ForeignKey(Project)
    
    def __unicode__(self):
        return self.name

class FeatureGroup(models.Model):
    name = models.CharField(max_length=200)
    description = models.TextField()
    
    release = models.ForeignKey(Release)

    def __unicode__(self):
        return self.name

class Feature(models.Model):
    name = models.CharField(max_length=200)
    PRIORITY_CHOICES = (
        ('1', 'P1'),
        ('2', 'P2'),
        ('3', 'P3')
    )
    priority = models.IntegerField(choices=PRIORITY_CHOICES)
    
    fgroup = models.ForeignKey(FeatureGroup)
    asker = models.ForeignKey(Asker, null=True)
    
    def __unicode__(self):
        return self.name
    
class FeatureDetail(models.Model):
    summary = models.TextField(max_length=1000)
    
    feature = models.ForeignKey(Feature)
    
    def __unicode__(self):
        return self.summary

class TechnicalArea(models.Model):
    name = models.CharField(max_length=200)
    description = models.TextField()
    
    lead = models.ForeignKey(Doer)
    release = models.ForeignKey(FeatureGroup)
    
    def __unicode__(self):
        return self.name
    
class TechnicalDetail(models.Model):
    name = models.CharField(max_length=200)
    description = models.TextField()
    estimated_days = models.IntegerField()
    
    area = models.ForeignKey(TechnicalArea)
    features = models.ManyToManyField(Feature, null=True)
    doer = models.ForeignKey(Doer)
    
    def __unicode__(self):
        return self.name